package modele;

import java.awt.Color;
import java.util.ArrayList;

import utils.Vector2d;

public class Noeud
{
	public int num;
	public Vector2d pos;
	int posi,posj;
	
	ArrayList<Lien> liens = new ArrayList<Lien>();
	public boolean	compris = false;
	public Color color;
	int type;
	
	int freq = 0;

	static int sid = 0;
	int id;
	private float	influence = 0;
	
	public Noeud(int i, int j, int i2, int j2, int k)
	{
		pos = new Vector2d(i, j);
		posi = i2;
		posj = j2;
		color = Color.green;
		type = k;
		
		id = sid;
		sid++;
	}

	public float distance(Noeud n)
	{
		return (float) Math.sqrt(Math.pow(pos.x-n.pos.x, 2 ) + Math.pow(pos.y-n.pos.y, 2 ));
	}

	public void addLien(Lien l)
	{
		liens.add(l);
	}

	public ArrayList<Noeud> developper( int type , float lim )
	{
		ArrayList<Noeud> a = new ArrayList<Noeud>();
		compris = true;

		a.add(this);
		boolean b = false;
		
		for( int i = 0 ; i < liens.size() ; i++ )
		{
			if( type == 1 )
				b = true;
			else if( type == 2 )
			{
				b = liens.get(i).stdDis < lim;
			}
			
			if( !liens.get(i).dest.compris && b )
			{
				//System.out.println("Lance");
				a.addAll( liens.get(i).dest.developper( type , lim ) );
			}
		}
		
		//System.out.println(a);
			
		return a;
	}

	public float distance(Vector2d p)
	{
		return (float) Math.sqrt(Math.pow(pos.x-p.x, 2 ) + Math.pow(pos.y-p.y, 2 ));

	}

	public String toString()
	{
		return pos.x + " " + pos.y + " (" + id + ")";
	}

	public Vector2d getPos()
	{
		return pos;
	}

	public void setInfluence(float influence)
	{
		this.influence = influence;
	}

	public float getInfluence()
	{
		return influence;
	}
}
